//
//  UseCarOverTime.m
//  xjairOA
//
//  Created by apple on 16-1-29.
//  Copyright (c) 2016年 net. All rights reserved.
//

#import "UseCarOverTime.h"

@implementation UseCarOverTime
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.picker.dataSource = self;
    self.picker.delegate = self;
    self.years = [NSArray arrayWithObjects:@"2016", @"2017", @"2018", @"2019", @"2020", @"2021", @"2022", @"2023", @"2024", @"2025", nil];
    self.months = [NSArray arrayWithObjects:@"01",@"02",@"03",@"04",@"05",@"06",@"07",@"08",@"09",@"10",@"11",@"12", nil];
    self.days = [NSArray arrayWithObjects:@"01",@"02",@"03",@"04",@"05",@"06",@"07",@"08",@"09",@"10",@"11",@"12",@"13",@"14",
                 @"15",@"16",@"17",@"18",@"19",@"20",@"21",@"22",@"23",@"24",@"25",@"26",@"27",@"28",@"29",@"30",@"31",nil];
    self.hours = [NSArray arrayWithObjects:@"00",@"01",@"02",@"03",@"04",@"05",@"06",@"07",@"08",@"09",@"10",@"11",@"12",@"13",@"14",
                  @"15",@"16",@"17",@"18",@"19",@"20",@"21",@"22",@"23",nil];
    self.minutes = [NSArray arrayWithObjects:@"00",@"10",@"20",@"30",@"40",@"50",nil];
    UIBarButtonItem * rightButton = [[UIBarButtonItem alloc] initWithTitle:@"完成" style:UIBarButtonSystemItemCancel target:self action:@selector(finish)];
    [self.navigationItem setRightBarButtonItem:rightButton];
}

-(void)finish
{
    NSInteger rowComponent0 = [self.picker selectedRowInComponent:0];//year
    NSInteger rowComponent1 = [self.picker selectedRowInComponent:1];//month
    NSInteger rowComponent2 = [self.picker selectedRowInComponent:2];//day
    NSInteger rowComponent3 = [self.picker selectedRowInComponent:3];//hour
    NSInteger rowComponent4 = [self.picker selectedRowInComponent:4];//minute
    UILabel * label5 = (UILabel*)[((UIViewController*)[self.navigationController.viewControllers objectAtIndex:2]).view viewWithTag:5];
    NSString * year = [self.years objectAtIndex:rowComponent0];
    NSString * month = [self.months objectAtIndex:rowComponent1];
    NSString * day = [self.days objectAtIndex:rowComponent2];
    NSString * hour = [self.hours objectAtIndex:rowComponent3];
    NSString * minute = [self.minutes objectAtIndex:rowComponent4];
    NSMutableString * string = [[NSMutableString alloc] init];
    [string appendString:year];
    [string appendString:@"-"];
    [string appendString:month];
    [string appendString:@"-"];
    [string appendString:day];
    [string appendString:@" "];
    [string appendString:hour];
    [string appendString:@":"];
    [string appendString:minute];
    label5.text = string;
    [self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:2] animated:YES];

}

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 5;
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    if(component==0){
        return self.years.count;
    }else if(component==1){
        return self.months.count;
    }else if(component==2){
        return self.days.count;
    }else if(component==3){
        return self.hours.count;
    }else{
        return self.minutes.count;
    }
    
}

- (NSString*)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    if(component==0){
        return [self.years objectAtIndex:row];
    }else if(component==1){
        return [self.months objectAtIndex:row];
    }else if(component==2){
        return [self.days objectAtIndex:row];
    }else if(component==3){
        return [self.hours objectAtIndex:row];
    }else{
        return [self.minutes objectAtIndex:row];
    }
    
}


@end
